# 作业
# 1.将上述的CRUD操作都距离重复一遍
# 2.自己做张表，4X4,表示当前接口是否可用。
# -------Create---Retrieve---Update---Delete-----
# -List--  √  ---  √   ---  √  ---  √  -----
# -Tuple-  ×  ---   √   ---  ×  ---  ×  -----
# -Dict--  √  ---   √   ---  √  ---  √  -----
# -Set---  √  ---   ×   ---  √  ---  √  -----
# ------------------------------------------------


# (1) List(列表)
# List——append(增加)
def list_append(mylist, *args):
    for value in args:
        mylist.append(value)
    return mylist


# List——insert(增加)
def list_insert(mylist, **kwargs):
    for key, value in kwargs.items():
        mylist.insert(value, key)
    return mylist


# List——Retrieve(检索)
def list_retrieve(mylist,value):
    if value not in mylist:
        return None
    return mylist.index(value)


# List——Update(更新)
def list_update(mylist, **kwargs):
    for key, value in kwargs.items():
        mylist[value] = key
    return mylist


# List——Delete(删除)
def list_delete(mylist, x):
    mylist.pop()
    mylist.remove(x)
    return mylist


# (2) Tuple(元组)——Retrieve(检索)
def tuple_retrieve(mytuple, v):
    if v not in my_tuple:
        return None
    return mytuple.index(v)


# (3) Dict(字典)
# Create(增加)
def dict_create(mydict, mydict2):
    mydict["role"] = "root"
    mydict.update(mydict2)
    print(mydict)
    mydict.setdefault("b", "terminal")
    print(mydict)


# Retrieve(检索)
def dict_retrieve(mydict,value):
    print(mydict["tree"])
    print(mydict.keys())
    print(mydict.values())
    print(mydict.items())
    return mydict.get(value, "io")


# Dict——Update(更新)
def dict_update(mydict, mydict2):
    mydict["tree"] = "reboot"
    mydict.update(mydict2)
    return mydict


# Dict——Delete(删除)
def dict_delete(mydict, k):
    mydict.pop(k)
    mydict.popitem()
    return mydict


# Create(增加)
def set_create(myset,v):
    myset.add(v)
    return myset


# Retrieve(检索)
def set_retrieve(myset,value):
    print(value in myset)
    return myset


# Dict——Update(更新)
def set_update(myset, mydict2):
    myset["tree"] = "reboot"
    return myset.update(myset)


# Set——Delete(删除)
def set_delete(myset, v):
    myset.remove(v)
    myset.discard("b")
    myset.pop()
    return myset


if __name__ == "__main__":
    my_list = ["w"]*2 + ["e"]
    my_tuple = (34, "string", None, True, 1, 2.3)
    my_dict = {"a": 1, "be": 2, "tree": 4}
    my_dict2 = {"star": 5, "c": 3}
    my_set = {"your", "age", "is", 5}
    my_set2 = {"four", 4, "hello"}
    # 列表
    print("List:")
    print(list_append(my_list, "d", "b"))
    print(list_insert(my_list, d=1, c=2))
    print(my_list[1:3], "\t", my_list[4], "\t", my_list[0:5:2])
    print(list_retrieve(my_list, "e"))
    print(list_update(my_list, cool=2, tree=5))
    print(list_delete(my_list, "tree"))
    # 统计和排序
    print(my_list.count("w"))
    my_list.sort()
    print(my_list)
    print(sorted(my_list, reverse=True))
    # 元组
    print("Tuple:")
    print(tuple_retrieve(my_tuple, "we"))
    print(tuple_retrieve(my_tuple, None))
    # 字典
    print(dict_create(my_dict, my_dict2))
    print(dict_retrieve(my_dict, "b"))
    print(dict_update(my_dict, my_dict2))
    print(dict_delete(my_dict, "tree"))
    my_dict2.clear()
    print(my_dict2)
    # 集合
    print(set_create(my_set, "true"))
    print(my_set.union(my_set2))
    print(set_delete(my_set, "age"))

